﻿Imports RabbitMQ.Client

Public Class Form1

    Private WithEvents MyEars As RabbitEars.RabbitEars

    Public Sub GotAMessage(ByVal sender As Object, ByVal consumerTag As String, ByVal deliveryTag As ULong, ByVal redelivered As Boolean, ByVal exchange As String, ByVal routingKey As String, ByVal properties As RabbitMQ.Client.IBasicProperties, ByVal body() As Byte) Handles MyEars.Message

        TxtOutput.Text &= System.Text.Encoding.UTF8.GetString(body) & vbCrLf

    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        txtHostname.Text = "192.168.10.90"
        txtPort.Text = -1
        txtVirtualHost.Text = "/"
        txtExchangeName.Text = "test"
        ComboExchangeType.SelectedIndex = 0
        txtQueueName.Text = "MyQue"
        txtRoutingKey.Text = "#"
        txtThrottle.Text = "0"
        CheckBoxDurable.Checked = True


        TxtOutput.Enabled = False
        GroupBox2.Enabled = False
        GroupBox1.Enabled = True
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        If Not MyEars Is Nothing Then MyEars.Close()
    End Sub

    Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click

        MyEars = New RabbitEars.RabbitEars() With {
            .HostName = txtHostname.Text,
            .Port = txtPort.Text,
            .VirtualHost = txtVirtualHost.Text,
            .ExchangeName = txtExchangeName.Text,
            .ExchangeWhatType = ComboExchangeType.Text,
            .QueueName = txtQueueName.Text,
            .RoutingKey = txtRoutingKey.Text,
            .Durable = CheckBoxDurable.Checked,
            .Throttle = 0}

        MyEars.Open(CheckBoxConsume.Checked)

        TxtOutput.Enabled = True
        GroupBox2.Enabled = True
        GroupBox1.Enabled = False
    End Sub

    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click
        MyEars.Send(TxtSend.Text)
    End Sub
End Class
